﻿
using System;
using System.Collections.Generic;
using System.Text;

using System.Linq;
using OddUserManager.Data.IRepositories;
using OddUserManager.Model;

namespace OddUserManager.Service.IServices
{
    public class AppUserService : IAppUserService
    {
        private readonly IAppUserRepository _repository;

        public AppUserService(IAppUserRepository appUserRepository)
        {
            _repository = appUserRepository;
        }

        public AppUser CheckUser(string userName, string password)
        {
            return _repository.CheckUser(userName, password);
        }

        public void DeleteBatchUsers(List<int> ids)
        {
            _repository.DeleteBatch(ids);
        }

        public void DeleteUserById(int id)
        {
            _repository.Delete(id);
        }

        public List<AppUser> GetAllUserList()
        {
            
            return _repository.GetAllList().ToList();
        }

        public AppUser GetUserById(int id)
        {
            //return _repository.Get(id);
            return _repository.GetWithRoles(id);
        }

        public bool InsertOrUpdateUser(AppUser dto)
        {
            var isSuccess = _repository.InsertOrUpdateUser(dto);
            return isSuccess;
        }

        public bool UpdateLoginTime(int id, DateTime lastLogonTime, int logonTimes)
        {
            return _repository.UpdateLogonTime(id, lastLogonTime, logonTimes);
        }
    }
}
